clear 

sort Country_Code year
xtset Country_Code year
gen lagged_Conflictoccurrence=l1.Conflictoccurrence
gen lagged_OilrentsofGDP=l1.OilrentsofGDP
gen lagged_Interaction_OIlConflict=l1.Interaction_OIlConflict
gen lagged_lnGDPpercapita=l1.ln_GDPpercapitaconstant2015US
gen lagged_GDPgrowth=l1.GDPgrowth
gen lagged_Trade=l1.TradeofGDP
gen lagged_Agedependency=l1.Agedependencyratioofworki
gen lagged_InteractionConflictOil=lagged_Conflictoccurrence*lagged_OilrentsofGDP
gen MilitaryAggression=lagged_Conflictoccurrence 

gen OilRentsDummy=1 if OilrentsofGDP>=2 
replace OilRentsDummy=0 if OilrentsofGDP<2
encode country, gen(Country_Code)
stset Yearsinoffice, fail(Politicalfailure)
sts graph, by(MilitaryAggression)
sts test MilitaryAggression
sts graph, by(OilRentsDummy)
sts test OilRentsDummy


encode Status, gen(Status_Code)
gen lagged_Status=l1.Status_Code

clonevar clone_PRCLFINAL=PRCLaverage
recode clone_PRCLFINAL (1=1 "Free") (1.5=1 "Free") (2=1 "Free") (2.5=1 "Free") (3=2 "Medium") (3.5=2 "Medium") (4=2 "Medium") (4.5=2 "Medium") (5=2 "Medium") (5.5=3 "Not free") (6=3 "Not free") (6.5=3 "Not free") (7=3 "Not free"), gen(Institutions)



***FINAL MODELS
stcox lagged_OilrentsofGDP i.year i.Country_Code, cluster (country)  nohr
stcox lagged_OilrentsofGDP i.year i.Country_Code, cluster (country)  
outreg2 using Model.doc, replace title (FinalFINAL!) dec(4)
stcox lagged_Conflictoccurrence i.year i.Country_Code, cluster (country)  nohr
stcox lagged_Conflictoccurrence i.year i.Country_Code, cluster (country)  
outreg2 using Model.doc, replace title (FinalFINAL!) dec(3)
stcox lagged_OilrentsofGDP lagged_Conflictoccurrence i.year i.Country_Code, cluster (country)  nohr
stcox lagged_OilrentsofGDP lagged_Conflictoccurrence i.year i.Country_Code, cluster (country)  
outreg2 using Model.doc, replace title (FinalFINAL!) dec(3)
stcox lagged_OilrentsofGDP lagged_Conflictoccurrence i.year i.Country_Code, cluster (country)  
stcox lagged_OilrentsofGDP lagged_Conflictoccurrence lagged_InteractionConflictOil i.year i.Country_Code, cluster (country) nohr
stcox lagged_OilrentsofGDP lagged_Conflictoccurrence lagged_InteractionConflictOil i.year i.Country_Code, cluster (country) 
outreg2 using Model.doc, replace title (FinalFINAL!) dec(3)
stcox lagged_OilrentsofGDP lagged_Conflictoccurrence lagged_InteractionConflictOil i.Institutions i.year i.Country_Code, cluster (country) nohr
stcox lagged_OilrentsofGDP lagged_Conflictoccurrence lagged_InteractionConflictOil i.Institutions i.year i.Country_Code, cluster (country) 
outreg2 using Model.doc, replace title (FinalFINAL!) dec(3)
stcox lagged_OilrentsofGDP lagged_Conflictoccurrence lagged_InteractionConflictOil i.Institutions lagged_lnGDPpercapita i.year i.Country_Code, cluster (country) nohr
stcox lagged_OilrentsofGDP lagged_Conflictoccurrence lagged_InteractionConflictOil i.Institutions lagged_lnGDPpercapita i.year i.Country_Code, cluster (country)
outreg2 using Model.doc, replace title (FinalFINAL!) dec(3)
stcox lagged_OilrentsofGDP lagged_Conflictoccurrence lagged_InteractionConflictOil i.Institutions lagged_GDPgrowth i.year i.Country_Code, cluster (country) nohr
stcox lagged_OilrentsofGDP lagged_Conflictoccurrence lagged_InteractionConflictOil i.Institutions lagged_GDPgrowth i.year i.Country_Code, cluster (country) 
outreg2 using Model.doc, replace title (FinalFINAL!) dec(3)
stcox lagged_OilrentsofGDP lagged_Conflictoccurrence lagged_InteractionConflictOil i.Institutions lagged_Trade i.year i.Country_Code, cluster (country) nohr
stcox lagged_OilrentsofGDP lagged_Conflictoccurrence lagged_InteractionConflictOil i.Institutions lagged_Trade i.year i.Country_Code, cluster (country) 
outreg2 using Model.doc, replace title (FinalFINAL!) dec(3)
stcox lagged_OilrentsofGDP lagged_Conflictoccurrence lagged_InteractionConflictOil i.Institutions lagged_Agedependency i.year i.Country_Code, cluster (country) nohr
stcox lagged_OilrentsofGDP lagged_Conflictoccurrence lagged_InteractionConflictOil i.Institutions lagged_Agedependency i.year i.Country_Code, cluster (country) 
outreg2 using Model.doc, replace title (FinalFINAL!) dec(3)
stcox lagged_OilrentsofGDP lagged_Conflictoccurrence lagged_InteractionConflictOil i.Institutions lagged_lnGDPpercapita lagged_GDPgrowth lagged_Agedependency lagged_Trade  i.year i.Country_Code, cluster (country) nohr
stcox lagged_OilrentsofGDP lagged_Conflictoccurrence lagged_InteractionConflictOil i.Institutions lagged_lnGDPpercapita lagged_GDPgrowth lagged_Agedependency lagged_Trade  i.year i.Country_Code, cluster (country) 
outreg2 using Model.doc, replace title (FinalFINAL!) dec(3)
stcox lagged_OilrentsofGDP lagged_Conflictoccurrence lagged_InteractionConflictOil i.Institutions lagged_lnGDPpercapita lagged_GDPgrowth lagged_Agedependency lagged_Trade  i.year i.Country_Code, cluster (country) 
stcox lagged_OilrentsofGDP lagged_Conflictoccurrence lagged_InteractionConflictOil i.Institutions lagged_lnGDPpercapita lagged_GDPgrowth lagged_Agedependency lagged_Trade i.year i.Country_Code, cluster (country) nohr
outreg2 using Model.doc, replace title (FinalFINAL!) dec(3)
stcox lagged_OilrentsofGDP lagged_Conflictoccurrence lagged_InteractionConflictOil i.Institutions lagged_lnGDPpercapita lagged_GDPgrowth lagged_Agedependency lagged_Trade i.year i.Country_Code, cluster (country) 

stcox c.lagged_OilrentsofGDP##i.lagged_Conflictoccurrence i.Institutions lagged_lnGDPpercapita lagged_GDPgrowth lagged_Agedependency lagged_Trade  i.year i.Country_Code, cluster (country) nohr
stcox c.lagged_OilrentsofGDP##i.lagged_Conflictoccurrence i.Institutions lagged_lnGDPpercapita lagged_GDPgrowth lagged_Agedependency lagged_Trade  i.year i.Country_Code, cluster (country) nohr
stcox OilRents MilitaryAggression InteractionOILLLMil i.Institutions   lagged_lnGDPpercapita lagged_GDPgrowth lagged_Agedependency lagged_Trade  i.year i.Country_Code, cluster (country) nohr
stcox c.OilRents##i.MilitaryAggression i.Institutions lagged_lnGDPpercapita lagged_GDPgrowth lagged_Agedependency lagged_Trade  i.year i.Country_Code, cluster (country) nohr

gen OilRents=lagged_OilrentsofGDP
margins, dydx( MilitaryAggression ) at (OilRents=(0(5)39))
marginsplot
margins, dydx( OilRents ) at (MilitaryAggression=(0(1)1))
marginsplot

